﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using Barbar.UrlGuard.BL;
using System.Globalization;

namespace Barbar.UrlGuard.Dal {
  public sealed class AuthenticationType : ILocalizable, ICloneable {
    private int m_Value;
    private string m_ResourceKey;
    private string m_Translation;

    private AuthenticationType(int value, string resourceKey) {
      m_Value = value;
      m_ResourceKey = resourceKey;
    }

    public int AuthenticationTypeID {
      get { return m_Value; }
    }

    public override string ToString() {
      ITranslator translator = ServiceLocator.Instance.Resolve<ITranslator>();
      return translator.Translate(CultureInfo.CurrentCulture.LCID, m_ResourceKey);
    }

    public static readonly AuthenticationType None = new AuthenticationType(0, "AuthenticationType_None");
    public static readonly AuthenticationType Basic = new AuthenticationType(1, "AuthenticationType_Basic");
    public static readonly AuthenticationType NTLM = new AuthenticationType(2, "AuthenticationType_NTLM");

    public static IEnumerable<AuthenticationType> GetAllTypes() {
      yield return (AuthenticationType)None.Clone();
      yield return (AuthenticationType)Basic.Clone();
      yield return (AuthenticationType)NTLM.Clone();
    }

    #region ILocalizable Members

    public void Localize(ILocalizator localizator) {
      if (localizator == null)
        throw new ArgumentNullException("localizator");
      m_Translation = localizator.Translate(m_ResourceKey);
    }

    #endregion

    #region ICloneable Members

    public object Clone() {
      return new AuthenticationType(m_Value, m_ResourceKey);
    }

    #endregion
  }
}
